#!/usr/bin/env ruby

#image rotation

## @example example8.rb
#  @see example8.c
#  @see example8.py


$LOAD_PATH << File.expand_path("../../../lib/rubyFulguro/fulguro")

require 'fulguro'
include Fulguro


imin   = flgr2d_load_pgm("../../images/gray/lena.pgm")
imtmp1 = FLGR_Data2D.new(imin)
imtmp2 = FLGR_Data2D.new(imin)
imout  = FLGR_Data2D.new(imin)
imdisc = FLGR_Data2D.new(imin)

w = imin.size_x
h = imin.size_y
mini = (h<w ? h:w)
radius = Integer((mini/2)/1.4143)


flgr2d_draw_disc(imdisc,w/2,h/2,radius,255)



scr0 = flgr2d_rtview_create(imin)

for i in 0..200
  flgr2d_rtview_refresh(scr0,imin)
end

for i in 0..359
  if i/180 == 1
    k = (i%180)-179
  else
    k = i
  end

  flgr2d_rotate_center(imout,imin,k)
  flgr2d_replace(imout,imdisc,"==",255,imout,0)
  flgr2d_rtview_refresh(scr0,imout)
end



## Create row link to imin and imout ehehe ;)
## you can also use flgr2d_create_pixmap_link
imlinkin_1  = FLGR_Data2D.new(imin,  0,imin.size_y/2-1);
imlinkin_2  = FLGR_Data2D.new(imin,  imin.size_y/2,imin.size_y-1);
imlinkout_1 = FLGR_Data2D.new(imout, 0,imout.size_y/2-1);
imlinkout_2 = FLGR_Data2D.new(imout, imout.size_y/2,imout.size_y-1);


for i in 0..359
  if i/180 == 1
    k = (i%180)-179
  else
    k = i
  end

  flgr2d_rotate_center(imlinkout_1,imlinkin_1,k)
  flgr2d_rotate_center(imlinkout_2,imlinkin_2,-1*k)
  flgr2d_rtview_refresh(scr0,imout)
end

for i in 0..200
  flgr2d_rtview_refresh(scr0,imout)
end
